<template>
    <div>
        <HomePageHead></HomePageHead>
        <HomePageNavigation></HomePageNavigation>
        <HomeSecondaryHeading :titleData="pageData" :pinyinid="routeId"></HomeSecondaryHeading>
        <!-- 频道页 -->
        <main class="index_main">
            
            <section class="channel_1 clearfix">
                <div class="channel_1_left">
                    <div class="channel_1_box">
                        <HomeSwiperSnscChannel></HomeSwiperSnscChannel>
                    </div>
                </div>
                <div class="channel_1_right">
                    <div class="channel_name_ul">
                        <div class="channel_name_ul_li" v-for="(per_obj, per_index) in 10" :key="per_obj">
                            <a class="channel_name_ul_li_tag" href="" title="">民工动态</a>
                            <a class="channel_name_ul_li_dot1 dot1" href="" title="">民工动态民工动态民工动态民工动态民工动态民工动态民工动态</a>
                        </div>
                    </div>
                </div>
            </section>
            <section class="channel_2 clearfix">
                <div class="channel_1_left clearfix">
                    <!--open 商贸活动-->
                    <div class="channel_head">
                        <div class="channel_head_name">商贸活动</div>
                        <a class="channel_head_more" href="" title=""> 栏目简介 </a>
                    </div>
                    <div class=" clearfix">
                        <div class="channel_1_box_1 clearfix">
                            <div class="channel_img_big_1_ul">
                                <div class="channel_img_big_1_li" v-for="(per_obj, per_index) in 1" :key="per_obj">
                                    <a class="channel_img_big_1_li_a" href="" title="">
                                        <img class="channel_img_big_1_li_img" src="../../public/img/8.png" title="" alt="">
                                        <div class="channel_img_big_1_li_dot1 dot1">
                                            农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权
                                        </div>
                                    </a>
                                </div>
                            </div>
                        </div>
                        <div class="channel_1_box_2 clearfix">
                            <div class="channel_ul_2">
                                <a class="channel_ul_2_a dot1" href="" title="" v-for="(per_obj, per_index) in 6"
                                    :key="per_obj">
                                    农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权
                                </a>
                            </div>
                        </div>
                    </div>
                    <!--end 商贸活动-->
                    <!--open 科教活动-->
                    <div class="channel_head">
                        <div class="channel_head_name">科教活动</div>
                        <a class="channel_head_more" href="" title=""> 栏目简介 </a>
                    </div>
                    <div class=" clearfix">
                        <div class="channel_1_box_1 clearfix">
                            <div class="channel_img_big_2_ul">
                                <div class="channel_img_big_2_li" v-for="(per_obj, per_index) in 1" :key="per_obj">
                                    <a class="channel_img_big_2_li_a" href="" title="">
                                        <img class="channel_img_big_2_li_img" src="../../public/img/8.png" title="" alt="">
                                        <div class="channel_img_big_2_li_dot1 dot1">
                                            农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权
                                        </div>
                                    </a>
                                </div>
                            </div>
                        </div>
                        <div class="channel_1_box_2 clearfix">
                            <div class="channel_ul_3">
                                <a class="channel_ul_3_a dot1" href="" title="" v-for="(per_obj, per_index) in 6"
                                    :key="per_obj">
                                    农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权
                                </a>
                            </div>
                        </div>
                    </div>
                    <!--end 科教活动-->
                </div>
                <div class="channel_1_right clearfix">
                    <!--open 产业动态-->
                    <div class="channel_head">
                        <div class="channel_head_name">产业动态</div>
                        <a class="channel_head_more" href="" title=""> 栏目简介 </a>
                    </div>
                    <div class="channel_img_big_3_ul clearfix">
                        <div class="channel_img_big_3_li" v-for="(per_obj, per_index) in 1" :key="per_obj">
                            <a class="channel_img_big_3_li_a" href="" title="">
                                <img class="channel_img_big_3_li_img" src="../../public/img/9.png" title="" alt="">
                                <div class="channel_img_big_3_li_dot1 dot1">
                                    特产商城特产商城特产商城特产商城特产商城特产商城特产商城特产商城特产商城</div>
                            </a>
                        </div>
                    </div>
                    <div class="channel_ul_4">
                        <div class="channel_ul_4_li dot1" v-for="(per_obj, per_index) in 6" :key="per_obj">
                            <div class="channel_ul_4_li_num">{{ per_index + 1 }}</div>
                            <a class="channel_ul_4_a dot1" href="" title="">农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权</a>
                        </div>
                    </div>
                    <!--end 产业动态-->
                </div>
            </section>
            <div class="channel_banner">
                <a class="channel_banner_a" href="" title="">
                    <img class="channel_banner_img" src="../../public/img/3.png" title="" alt="">
                </a>
            </div>
            <section class="channel_3 clearfix">
                <!--open 农贸节庆-->
                <div class="channel_1_left clearfix">
                    <div class="channel_head">
                        <div class="channel_head_name">农贸节庆</div>
                        <a class="channel_head_more" href="" title=""> 栏目简介 </a>
                    </div>
                    <div class=" clearfix">
                        <div class="channel_1_box_1 clearfix">
                            <div class="channel_img_big_4_ul">
                                <div class="channel_img_big_4_li" v-for="(per_obj, per_index) in 1" :key="per_obj">
                                    <a class="channel_img_big_4_li_a" href="" title="">
                                        <img class="channel_img_big_4_li_img" src="../../public/img/8.png" title="" alt="">
                                        <div class="channel_img_big_4_li_dot2 dot2">
                                            农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权
                                        </div>
                                    </a>
                                </div>
                            </div>
                            <div class="channel_img_ul_1 clearfix">
                                <div class="channel_img_ul_1_li" v-for="(per_obj, per_index) in 2" :key="per_obj">
                                    <a class="channel_img_ul_1_li_a" href="" title="">
                                        <img class="channel_img_ul_1_li_img" src="../../public/img/9.png" title="" alt="">
                                        <div class="channel_img_ul_1_li_dot2 dot2">
                                            农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权
                                        </div>
                                    </a>
                                </div>
                            </div>
                        </div>
                        <div class="channel_1_box_2 clearfix">
                            <div class="channel_ul_5">
                                <a class="channel_ul_5_a dot1" href="" title="" v-for="(per_obj, per_index) in 10"
                                    :key="per_obj">
                                    农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
                <!--end 农贸节庆-->
                <!--open 市场行情-->
                <div class="channel_1_right clearfix">
                    <div class="channel_head">
                        <div class="channel_head_name">市场行情</div>
                        <a class="channel_head_more" href="" title=""> 栏目简介 </a>
                    </div>
                    <div class="channel_img_ul_2 clearfix">
                        <div class="channel_img_ul_2_li" v-for="(per_obj, per_index) in 2" :key="per_obj">
                            <a class="channel_img_ul_2_li_a" href="" title="">
                                <img class="channel_img_ul_2_li_img" src="../../public/img/9.png" title="" alt="">
                                <div class="channel_img_ul_2_li_dot1 dot1">
                                    农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权</div>
                            </a>
                        </div>
                    </div>
                    <div class="channel_ul_6">
                        <a class="channel_ul_6_a dot1" href="" title="" v-for="(per_obj, per_index) in 6"
                            :key="per_obj">
                            农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权
                        </a>
                    </div>
                    <!--end 市场行情-->
                </div>
            </section>
            <section class="channel_4 clearfix">
                <div class="channel_1_left clearfix">
                    <!--open 业界交流-->
                    <div class="channel_head">
                        <div class="channel_head_name">业界交流</div>
                        <a class="channel_head_more" href="" title=""> 栏目简介 </a>
                    </div>
                    <div class="channel_ul_7">
                        <a class="channel_ul_7_a dot1" href="" title="" v-for="(per_obj, per_index) in 6"
                            :key="per_obj">
                            农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权
                        </a>
                    </div>
                    <!--end 业界交流-->
                </div>
                <!--open 主题活动-->
                <div class="channel_1_right clearfix">
                    <div class="channel_head">
                        <div class="channel_head_name">主题活动</div>
                        <a class="channel_head_more" href="" title=""> 栏目简介 </a>
                    </div>
                    <div class="channel_img_big_5_ul">
                        <div class="channel_img_big_5_li" v-for="(per_obj, per_index) in 1" :key="per_obj">
                            <a class="channel_img_big_5_li_a" href="" title="">
                                <img class="channel_img_big_5_li_img" src="../../public/img/8.png" title="" alt="">
                                <div class="channel_img_big_5_li_dot2 dot2">
                                    农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权农民工维权</div>
                            </a>
                        </div>
                    </div>
                    <!--end 主题活动-->
                </div>
            </section>
        </main>
        <!-- 页脚部分 -->
        <HomeFoot1></HomeFoot1>
    </div>
</template>

<script setup>
//0.加载页面依赖 start ---------------------------------------->
import { ref, onMounted } from 'vue';
import { ElMessage } from 'element-plus';
//0.加载页面依赖 end ---------------------------------------->

//1.获得路由id start ---------------------------------------->
const targetSegment = getRoutePath(1);
//1.1 获得当前的路由id
let routeId;
//通过导航路径反向查询导航id
const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
    method: 'GET',
    query: {
        'pinyin': targetSegment,
    },
});
if (getRouteId.code == 200) {
    routeId = getRouteId.data.category_id
} else {
    console.log("获得路由id出错！", getRouteId.message)
}
//1.获得路由id end ---------------------------------------->

//2.选项卡 start ---------------------------------------->
let showTabs = ref(1)
let qhtabs = function (number) {
    console.log(number)
    showTabs.value = number
}
//2.选项卡 end ---------------------------------------->

//3.广告 start ---------------------------------------->
let adImg1 = ref({})
let adImg2 = ref({})
let adImg3 = ref({})
let adImg4 = ref({})
onMounted(async () => {
    //从客户端获取行政职能部门 加快打开速度
    const { $webUrl, $CwebUrl } = useNuxtApp();
    //广告1
    let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snzxw_category_0001`
    const responseAd1 = await fetch(url, {
        headers: {
            'Content-Type': 'application/json',
            'Userurl': $CwebUrl,
            'Origin': $CwebUrl
        }
    });
    const resultAd1 = await responseAd1.json();
    adImg1.value = resultAd1.data[0];

    //广告2
    let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snzxw_category_0002`
    const responseAd2 = await fetch(url2, {
        headers: {
            'Content-Type': 'application/json',
            'Userurl': $CwebUrl,
            'Origin': $CwebUrl
        }
    });
    const resultAd2 = await responseAd2.json();
    adImg2.value = resultAd2.data[0];

    //广告3
    let url3 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snzxw_category_0003`
    const responseAd3 = await fetch(url3, {
        headers: {
            'Content-Type': 'application/json',
            'Userurl': $CwebUrl,
            'Origin': $CwebUrl
        }
    });
    const resultAd3 = await responseAd3.json();
    adImg3.value = resultAd3.data[0];

    //广告4
    let url4 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snzxw_category_0004`
    const responseAd4 = await fetch(url4, {
        headers: {
            'Content-Type': 'application/json',
            'Userurl': $CwebUrl,
            'Origin': $CwebUrl
        }
    });
    const resultAd4 = await responseAd4.json();
    adImg4.value = resultAd4.data[0];
})
//3.广告 end ---------------------------------------->

//4.页面数据 start ---------------------------------------->
const pageData = ref([
    //示例：
    // {
    //     id: 1, 
    //     title: "", //该导航的标题
    //     data: [], //数据1
    //     data1: [], //数据2
    //     data2: [], //数据3
    //     data3: [], //数据4
    //     data4: [], //数据5
    //     category_id1: "",  //子导航id1
    //     category_id2: "", 
    //     category_id3: "",
    //     category_id4: "",
    //     title1: "", //子导航标题1
    //     title2: "",
    //     title3: "",
    //     title4: "",
    //     cid: "" //该导航的id
    // },
])

//4.1 获取所有导航
try {
    const navigateData = await requestDataPromise('/web/getWebsiteModelCategory', {
        method: 'GET',
        query: {
            'placeid': 1,
            'pid': routeId,
            'num': 8
        },
    });
    if (navigateData.code == 200) {
        // 遍历可用的导航池放到页面中
        for (let index in navigateData.data) {
            let data = {
                title: navigateData.data[index].name,
                cid: navigateData.data[index].category_id,
                children_count: navigateData.data[index].children_count,
                alias: navigateData.data[index].alias,
                aLIas_pinyin: targetSegment + "/" + navigateData.data[index].aLIas_pinyin,
                data: [],
                data1: [],
                data2: [],
                data3: [],
                data4: [],
                category_id1: "",
                category_id2: "",
                category_id3: "",
                category_id4: "",
                title1: "",
                title2: "",
                title3: "",
                title4: ""
            };
            if (navigateData.data[index].is_url == 1) {
                // 处理 URL 的逻辑
            } else {
                //每个页面最多8个模块
                pageData.value.push(data);
            }
        }
        //导航池加载完毕，开始申请模块数据
        let getJson = [
            { "parent": routeId + ",0,0", "child": pageData.value[0].cid + ",5,7" },//模块1理论前沿
            { "parent": routeId + ",0,0", "child": pageData.value[1].cid + ",3,11" },//模块2典型经验
            { "parent": routeId + ",0,0", "child": pageData.value[2].cid + ",4,2" },//模块3农业天地
            { "parent": routeId + ",0,0", "child": pageData.value[3].cid + ",3,10" },//模块4美丽乡村
            { "parent": routeId + ",0,0", "child": pageData.value[4].cid + ",3,10" },//模块5农民之家
            { "parent": routeId + ",0,0", "child": pageData.value[5].cid + ",0,7" },//模块6农业天地
            //{ "parent": routeId + ",0,0", "child": pageData.value[6].cid + ",2,3" },//模块7农村建设
            //{ "parent": routeId + ",0,0", "child": pageData.value[7].cid + ",4,0" },//模块8高端资讯
        ]
        let jsonString = JSON.stringify(getJson);
        getPageAllData(jsonString);

    } else {
        console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
        console.log("错误位置：分类页导航池")
        console.log("后端错误反馈：", navigateData.message)
        console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
    }
} catch (error) {
    console.log("错误：导航池渲染执行接口出错！请检查频道页渲染的模块数据是否完整！")
}


async function getPageAllData(jsonString) {
    const mkdata = await requestDataPromise('/web/getWebsiteAllArticle', {
        method: 'GET',
        query: {
            'id': jsonString
        },
    });

    if (mkdata.code == 200) {
        //模块1
        pageData.value[0].data = mkdata.data[0].child.imgnum;
        pageData.value[0].data2 = mkdata.data[0].child.textnum;
        //模块2
        for(let index in mkdata.data[1].child.imgnum){
            if(index==0){
                pageData.value[1].data.push(mkdata.data[1].child.imgnum[index]);
            }else{
                pageData.value[1].data2.push(mkdata.data[1].child.imgnum[index]);
            }
        }
        pageData.value[1].data3 = mkdata.data[1].child.textnum;
        //模块3
        for(let index in mkdata.data[2].child.imgnum){
            if(index<=1){
                pageData.value[2].data.push(mkdata.data[2].child.imgnum[index]);
            }else{
                pageData.value[2].data2.push(mkdata.data[2].child.imgnum[index]);
            }
        }
        pageData.value[2].data3 = mkdata.data[2].child.textnum;
        //模块4
        pageData.value[3].data = mkdata.data[3].child.textnum;
        pageData.value[3].data2 = mkdata.data[3].child.imgnum;
        //模块5
        pageData.value[4].data = mkdata.data[4].child.textnum;
        pageData.value[4].data2 = mkdata.data[4].child.imgnum;
        //模块6
        pageData.value[5].data = mkdata.data[5].child.textnum;

    } else {
        ElMessage.error(mkdata.message)
    }
}
//4.页面数据 end ---------------------------------------->

//5.设置seo信息 start---------------------------------------->
const setData = await requestDataPromise('/web/getWebsiteCategoryHead', {
    method: 'GET',
    query: {
        'catid': routeId
    },
});

if (setData.code == 200) {
    let seoTitle = setData.data.seo_title;
    let seoDescription = setData.data.seo_description;
    let seoKeywords = setData.data.seo_keywords;
    let seoSuffix = setData.data.suffix;
    let seoName = setData.data.website_name;

    useSeoMeta({
        title: seoTitle + "_" + seoSuffix,
        meta: [
            { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
            { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 }
        ]
    });
} else {
    console.log("设置频道页SEO出错！",setData.message)
}
//5.设置seo信息 end---------------------------------------->
</script>

<style lang="less" scoped>
@import '@/assets/css/class.less';
</style>